var chosen = "";
var vote_xmlhttp;
function ajaxVote(){
	
	vote_xmlhttp=new XMLHttpRequest();
	if (vote_xmlhttp==null){
		alert ("An error occurred. Please update your browser.");
		return;
	}
	
	var subs = document.getElementById("subscription").value;
	chosen = "";
	if (document.getElementById("answerA").checked) {
		chosen = document.getElementById("answerA").value;
	}
	if (document.getElementById("answerB").checked) {
		chosen = document.getElementById("answerB").value;
	}
	if (chosen == "") {
		alert("You must choose an answer");
		return;
	}

	var extracto = document.URL.substring(0, document.URL.indexOf("/servlets/"));
	//extracto = extracto.replace("history", "addVote");
	var url = extracto + "/servlets/room/addVote?subscription=" + subs + "&answer=" + chosen// + "&image="+Math.random();
	
	vote_xmlhttp.onreadystatechange=VotestateChanged;
	vote_xmlhttp.open("GET",url,true);
	vote_xmlhttp.send(null);
}

function VotestateChanged(){
	
	if (vote_xmlhttp.readyState==4){
		document.getElementById("answerA").disabled = true; 
		document.getElementById("answerB").disabled = true; 
		$("#vote").button( "option", "disabled", true );
		
	}
}